home *** CD-ROM | disk | FTP | other *** search
Wrap
/**------------------------------------*------------------------------------** RELEASED TO THE PUBLIC DOMAIN BY CODEWORKS DEVELOPMENT, DECEMBER 1993. You may freely copy, distribute and reuse the code in this example. Codeworks disclaims any warranty of any kind, expressed or implied, as to its fitness for any particular use. Author: Andrew Vyrros, av@codeworks.com **------------------------------------*------------------------------------**/ /**------------------------------------*------------------------------------** File: Star.m Project: DynaDoodle/Star.bproj Info: Implementation of the Star class. **------------------------------------*------------------------------------**/ #import "Star.h" #import <appkit/appkit.h> #define NAME NXLocalizedStringFromTableInBundle("Doodle.strings", [NXBundle bundleForClass:[Star class]], "Name", "Star", "Name of Star Doodle") #define DESCRIPTION NXLocalizedStringFromTableInBundle("Doodle.strings", [NXBundle bundleForClass:[Star class]], "Description", "A multi-point star. You can change the number of points and the length of the points.", "Description of Star Doodle") @implementation Star - initFrame:(const NXRect *)f { [super initFrame:f]; numPoints = 8; pointRatio = 1.0; troughRatio = 0.5; return self; } - didLoadNib { numPoints = [numPointsSlider intValue]; pointRatio = [pointRatioSlider floatValue]; troughRatio = [troughRatioSlider floatValue]; return self; } - drawSelf:(const NXRect *)rects :(int)rectCount { float theta, thetaStepD2; NXPoint center, p; NXCoord rPeak, rTrough; int i; NXSetColor(backgroundColor); NXRectFill(&bounds); NXSetColor(foregroundColor); thetaStepD2 = (M_PI * 2) / numPoints / 2.0; center.x = bounds.origin.x + bounds.size.width / 2.0; center.y = bounds.origin.y + bounds.size.height / 2.0; rPeak = pointRatio * MIN(bounds.size.width, bounds.size.height) / 2.0; rTrough = rPeak * troughRatio; theta = M_PI_2; PSmoveto(center.x, center.y + rPeak); i = numPoints; while (i--) { theta -= thetaStepD2; p.x = center.x + rTrough * cos(theta); p.y = center.y + rTrough * sin(theta); PSlineto(p.x, p.y); theta -= thetaStepD2; p.x = center.x + rPeak * cos(theta); p.y = center.y + rPeak * sin(theta); PSlineto(p.x, p.y); } PSfill(); return self; } - takeNumPointsFrom:sender { numPoints = [[sender selectedCell] intValue]; [self update]; return self; } - takePointRatioFrom:sender { pointRatio = [[sender selectedCell] floatValue]; [self update]; return self; } - takeTroughRatioFrom:sender { troughRatio = [[sender selectedCell] floatValue]; [self update]; return self; } @end